

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var color_sensor = "#28BFE6";





    //rgb超声波模块初始化
    Blockly.Blocks.microbit_rgbUltrasonicInit = {
        init:function(){
        this.setColour("#28BFE6");
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_ULTRASONICPIN)
        .appendField(Blockly.Msg.MICROBIT_IOPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
        ]),"ioPort")
        .appendField(Blockly.Msg.MICROBIT_RGBPORT)
        .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
        ]),"rgbPort")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    //RGB超神波传感器读取距离
    Blockly.Blocks.microbit_rgbUltrasonicDistance = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICDISTANCE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
        }
    };

     //设置RGB超声波灯珠颜色
     Blockly.Blocks.microbit_rgbUltrasonicColor = {
        init:function(){
        this.setColour(color_sensor);
        this.appendDummyInput("")
        .appendField(new Blockly.FieldImage(staticImg+"/52.RGB ultrasonic Module.svg", 84, 42))
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICCOLOR)
                .appendField(new Blockly.FieldDropdown([
                    [Blockly.Msg.MICROBIT_RGBULTRASONICLEFT, "left"],
                    [Blockly.Msg.MICROBIT_RGBULTRASONICRIGHT, "right"],
                    [Blockly.Msg.MICROBIT_RGBULTRASONICTWO, "double"],
                ]),"rgbLight")
                .appendField(Blockly.Msg.MICROBIT_RGBULTRASONICSPECIAL)
                .appendField(new Blockly.FieldDropdown([
                    [Blockly.Msg.MICROBIT_RGBBREATHING, "breathing"],
                    [Blockly.Msg.MICROBIT_RGBROTATE, "rotate"],
                    [Blockly.Msg.MICROBIT_RGBFLICKER, "flicker"],
                ]),"rgbSpecial")
                this.appendValueInput("rgbBrightness", Number)
                .appendField(Blockly.Msg.MICROBIT_BRIGHTNESS)
                this.appendValueInput("COLOR", Number)
                .appendField(Blockly.Msg.MICROBIT_DISPLAYCOLOR)
                // this.appendValueInput("rgbUlr", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBR)
                // this.appendValueInput("rgbUlg", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBG)
                // this.appendValueInput("rgbUlb", Number)
                // .appendField(Blockly.Msg.MICROBIT_RGBB)            
                this.setPreviousStatement(true,null);
                this.setNextStatement(true,null);
                this.setTooltip('');
        }
    };

    return Blockly;
}

module.exports = SensorbitUnoBlocks;

